package pokerLogic2;

import neuroPoker.poker.Enums.HandValues;
import neuroPoker.poker.Enums.Stages;

public class ActionChecker {
	public StartHandPlayer startHandPlayer;

	public BetRoundChecker betRoundChecker;

	public BlattChecker blattChecker;

	public WaWbChecker waWbChecker;

	public RiverPlayer riverHUPlayer;

	public Bluffer bluffer;

	public HUStandardMover huStdMover;

	public PokerInfo pokerInfo;

	public ActionHistory actionHistory;

	public ActionChecker(PokerInfo pokerInfo) {
		this.pokerInfo = pokerInfo;
		actionHistory = new ActionHistory();
		blattChecker = new BlattChecker(pokerInfo, pokerInfo
				.getPotSizeChecker());
		betRoundChecker = new BetRoundChecker(blattChecker, actionHistory);
		bluffer = new Bluffer(betRoundChecker, pokerInfo.getPositionChecker());
		huStdMover = new HUStandardMover(betRoundChecker, actionHistory);
		waWbChecker = new WaWbChecker(betRoundChecker);
		riverHUPlayer = new RiverPlayer(betRoundChecker, waWbChecker,
				actionHistory);
		startHandPlayer = new StartHandPlayer(pokerInfo.getInChecker(),
				pokerInfo.getPositionChecker(), pokerInfo.getDealerFinder(),
				pokerInfo);
	}

	public Action getAction(int invested) {
		pokerInfo.checkInfo();
		Action action = getStdAction();
		action = betRoundChecker.check(action, invested);
		action = blattChecker.getPotOddsAction(action);
		action = bluffer.getAction(pokerInfo.getSitzPosition(), action,
				invested);
		action = huStdMover.check(action, invested);
		action = waWbChecker.check(action, invested);
		action = riverHUPlayer.getAction(action);
		actionHistory.saveAction(action, pokerInfo.getKosten(), pokerInfo
				.getStage(), pokerInfo.getHandCounter().getGameNr(), pokerInfo
				.getInSpieler(), startHandPlayer.gamePosition, pokerInfo
				.getStage() == Stages.preFlop ? HandValues.nix
				: blattChecker.handValue);
		return action;
	}

	private Action getStdAction() {
		Action action;
		if (pokerInfo.getStage() == Stages.preFlop)
			action = startHandPlayer.getAction(pokerInfo.getHand(),
					Global.bigBlind);
		else
			action = blattChecker.getAction(pokerInfo.getTableCardReader()
					.isRiverDealt());
		return action;
	}
}
